package com.fzrskj.cloud.free.user.service;


import com.fzrskj.cloud.free.core.enums.DicParamEnum;
import com.fzrskj.cloud.free.dic.dao.DicParamDao;
import com.fzrskj.cloud.free.sys.bean.SysMiniServiceBean;
import com.fzrskj.cloud.free.sys.utils.SysMiniServiceUtils;
import ms.core.consts.SysErr;
import ms.core.object.CObject;
import ms.core.tool.JsonTool;
import ms.core.tool.XmlCodeParser;
import org.apache.commons.collections.map.HashedMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * ThridAuthToolService.
 *获取第三方登录工具方法
 * @author ch.
 *         Created on 2020/1/13 0011.
 */
public class ThridAuthToolService extends CObject {
    public String qryQQAuthParam(HttpServletRequest req, HttpServletResponse resp, String p, String sid) {
        DicParamDao dicParamDao = new DicParamDao();
        String qqLogo = dicParamDao.getParamValue(DicParamEnum.AUTH_QQ_LOGO.getVal());
        String toolId = dicParamDao.getParamValue(DicParamEnum.AUTH_TOOL_SERVERID.getVal());
        if("".equals(toolId) ||  toolId == null){
            return XmlCodeParser.formatResultTips(true, SysErr.SYS_PARAM_ERR);
        }
        Integer toolServerId = Integer.parseInt(toolId);
        SysMiniServiceUtils miniServiceUtils = new SysMiniServiceUtils();
        SysMiniServiceBean miniServiceBean = miniServiceUtils.querySysMiniService(toolServerId);
        String authParamUrl = dicParamDao.getParamValue(DicParamEnum.AUTH_PARAM_URL.getVal());
        String openQqLogin = dicParamDao.getParamValue(DicParamEnum.OPEN_QQ_LOGIN.getVal());
        String result = "";
        if(miniServiceBean == null){
            return XmlCodeParser.formatResultTips(true, SysErr.SYS_PARAM_ERR);
        }
        Map<String, Object> dataMap = new HashedMap();
        dataMap.put("qqLogo",qqLogo);
        dataMap.put("param",miniServiceBean.getMetadata());
        dataMap.put("authParamUrl",authParamUrl);
        dataMap.put("openQqLogin",openQqLogin);
        JsonTool.mapToJson(dataMap);
        return XmlCodeParser.formatResultData(true,"S000",JsonTool.mapToJson(dataMap));
    }

}
